package com.codi.bus.core.service.organ.impl;

import com.codi.base.util.Assert;
import com.codi.bus.core.dao.OrgFileBucketDao;
import com.codi.bus.core.domain.OrgFileBucket;
import com.codi.bus.core.service.impl.BankServiceImpl;
import com.codi.bus.core.service.organ.OrgFileBucketService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by wangzhenhao on 2017/9/7.
 */
@Service
@Transactional(readOnly = true)
public class OrgFileBucketServiceImpl extends BankServiceImpl implements OrgFileBucketService{
    @Resource
    private OrgFileBucketDao orgFileBucketDao;

    @Override
    @Transactional(readOnly = false)
    public OrgFileBucket add(OrgFileBucket record) {
        //validate
        Assert.notNull(record);
        Assert.notNull(record.getBucketCode());
        Assert.notNull(record.getHostName());

        Date now = new Date();
        record.setCreateDate(now);
        record.setUpdateDate(now);

        orgFileBucketDao.insertSelective(record);

        return record;
    }

    @Override
    @Transactional(readOnly = false)
    public int update(OrgFileBucket record) {
        Assert.notNull(record);
        Assert.notNull(record.getBucketId());
        Assert.notNull(record.getBucketCode());
        Assert.notNull(record.getHostName());

        record.setCreateDate(null);
        record.setUpdateDate(new Date());

        return orgFileBucketDao.updateByPrimaryKeySelective(record);
    }

    @Override
    @Transactional(readOnly = false)
    public int delete(Long bucketId) {
        return orgFileBucketDao.deleteByPrimaryKey(bucketId);
    }

    @Override
    public List<OrgFileBucket> query() {
        return orgFileBucketDao.queryList();
    }

    @Override
    public OrgFileBucket query(Long bucketId) {
        return orgFileBucketDao.selectByPrimaryKey(bucketId);
    }
}
